package cn.kgc.springboot.day03.controller;

import cn.kgc.springboot.day03.entity.User;
import cn.kgc.springboot.day03.service.UserService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 课工场
 * @date 2024/3/20
 * @description
 */
@RestController
@RequestMapping("user")
public class UserController {


    @Resource
    private UserService userService;

    // 查询所有
    @GetMapping("list")
    public Map<String,Object> selectAll(){
        HashMap<String, Object> result = new HashMap<>();
        List<User> list = userService.list();
        result.put("data",list);
        result.put("code",200);
        return  result;
    }

    // 查询所有
    @GetMapping("{id}")
    public Map<String,Object> deleteById(@PathVariable("id") Integer id){
        HashMap<String, Object> result = new HashMap<>();
        boolean b = userService.removeById(id);
        result.put("msg",b);
        result.put("code",200);
        return  result;
    }

}
